package com.xiongxiong.yiqing.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiongxiong.yiqing.exception.Asserts;
import com.xiongxiong.yiqing.mapper.RecordCardMapper;
import com.xiongxiong.yiqing.mapper.SysUserMapper;
import com.xiongxiong.yiqing.pojo.SysUser;
import com.xiongxiong.yiqing.pojo.vo.FindSysUserCondition;
import com.xiongxiong.yiqing.pojo.vo.LoginVO;
import com.xiongxiong.yiqing.pojo.vo.SysUserVO;
import com.xiongxiong.yiqing.pojo.vo.count.CountYinYangPic;
import com.xiongxiong.yiqing.service.CountService;
import com.xiongxiong.yiqing.service.RecordCardService;
import com.xiongxiong.yiqing.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 熊熊很酷
 * @since 2022-12-14
 */
@Service
public class CountServiceImpl implements CountService {

    @Autowired
    private SysUserService sysUserService;

    @Autowired
    private RecordCardService recordCardService;

    @Autowired
    private RecordCardMapper recordCardMapper;

    /**
     * 今日打卡阴阳分析饼图
     * @return java.util.List<com.xiongxiong.yiqing.pojo.vo.count.CountYinYangPic>
     * @author 熊林飞
     * @date: 2023/2/14 13:51
     */
    @Override
    public List<CountYinYangPic> yinYangPic() {
        List<CountYinYangPic> countYinYangPics = recordCardMapper.yinYangPic();
        System.out.println(countYinYangPics);
        // 计数未打卡人数
        long count = sysUserService.count();
        long x = countYinYangPics.stream().mapToLong(CountYinYangPic::getValue).sum();
        countYinYangPics.add(new CountYinYangPic("未打卡", (int) (count-x)));
        return countYinYangPics;
    }

    /**
     * 近n天打卡数量统计
     * List<CountYinYangPic>
     * @param dayNub 前多少天数据
     * @return java.util.List<com.xiongxiong.yiqing.pojo.vo.count.CountYinYangPic>
     * @author 熊林飞
     * @date: 2023/2/14 14:44
     */
    @Override
    public List<CountYinYangPic> recordByDayLine(Integer dayNub) {
        List<CountYinYangPic> countYinYangPics = recordCardMapper.recordByDayLine(dayNub);
        System.out.println(countYinYangPics);
        return countYinYangPics;
    }
}
